package com.lg.happyfarmer.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.lg.happyfarmer.R;
import com.lg.happyfarmer.base.BaseActivity;
import com.lg.happyfarmer.base.BaseUtil;
import com.lg.happyfarmer.snackbar.BaseTransientBottomBar;
import com.lg.happyfarmer.snackbar.TopSnackBar;
import com.lg.happyfarmer.untils.UserUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import xtom.frame.XtomActivityManager;

/**
 * 性别选择
 * Created by Torres on 2018/3/30 0030.
 */

public class SexSelectActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.ib_back)
    ImageButton ib_back;
    @Bind(R.id.btn_test)
    Button btn_test;
    @Bind(R.id.iv_femal)
    ImageView iv_femal;
    @Bind(R.id.iv_man)
    ImageView iv_man;

    private int status = 0;//1 男 0 nv
    private int man = 0;//1 选中0 未选中
    private int femal = 0;//1 选中0 未选中
    @Bind(R.id.ll_all)
    LinearLayout ll_all;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_sexselect);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
        BaseUtil.startLayoutAnim(mContext, ll_all);
    }

    @Override
    protected void callBeforeDataBack(HemaNetTask netTask) {
        super.callBeforeDataBack(netTask);
    }

    @Override
    protected void callAfterDataBack(HemaNetTask netTask) {
        super.callAfterDataBack(netTask);
    }

    @Override
    protected void callBackForServerSuccess(HemaNetTask netTask, HemaBaseResult baseResult) {
        super.callBackForServerSuccess(netTask, baseResult);
    }

    @Override
    protected void callBackForServerFailed(HemaNetTask netTask, HemaBaseResult baseResult) {
        super.callBackForServerFailed(netTask, baseResult);
    }

    @Override
    protected void callBackForGetDataFailed(HemaNetTask netTask, int failedType) {
        super.callBackForGetDataFailed(netTask, failedType);
    }

    @Override
    protected void findView() {

        super.findView();
    }

    @Override
    protected void getExras() {
        super.getExras();
    }

    @Override
    protected void setListener() {
        super.setListener();
        btn_test.setOnClickListener(this);
        ib_back.setOnClickListener(this);
        iv_femal.setOnClickListener(this);
        iv_man.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Intent it = null;
        switch (view.getId()) {
            case R.id.iv_femal:
                if (femal == 0) {
                    femal = 1;
                    man = 0;
                    iv_man.setImageResource(R.mipmap.icon_nochoice);
                    iv_femal.setImageResource(R.mipmap.icon_correct);
                    btn_test.setEnabled(true);
                } else {
                    femal = 0;
                    man = 0;
                    iv_man.setImageResource(R.mipmap.icon_nochoice);
                    iv_femal.setImageResource(R.mipmap.icon_nochoice);
                    btn_test.setEnabled(false);
                }
                break;
            case R.id.iv_man:
                if (man == 0) {
                    man = 1;
                    femal = 0;
                    iv_femal.setImageResource(R.mipmap.icon_nochoice);
                    iv_man.setImageResource(R.mipmap.icon_correct);
                    btn_test.setEnabled(true);
                } else {
                    man = 0;
                    femal = 0;
                    iv_femal.setImageResource(R.mipmap.icon_nochoice);
                    iv_man.setImageResource(R.mipmap.icon_nochoice);
                    btn_test.setEnabled(false);
                }
                break;
            case R.id.ib_back:
                backToLoginActivity();
                break;
            case R.id.btn_test:
                it = new Intent(mContext, BirthdayActivity.class);
                startActivity(it);

                break;
        }
    }

    //从性别返回到登录页面
    public void backToLoginActivity() {
        Activity selectLoginActivity = (SelectLoginActivity) XtomActivityManager.getActivityByClass(SelectLoginActivity.class);
        if (selectLoginActivity != null) {
            XtomActivityManager.finishOtherActivity(selectLoginActivity);
        } else {
            XtomActivityManager.finishAll();
            Intent intentLogin = new Intent(mContext, SelectLoginActivity.class);
            startActivity(intentLogin);
        }
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            backToLoginActivity();
        }
        return super.onKeyDown(keyCode, event);
    }
}
